package com.heima.feigns.fallback;

import com.heima.feigns.AdminFeign;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class AdminFeignFallback implements FallbackFactory<AdminFeign> {
    @Override
    public AdminFeign create(Throwable throwable) {
        throwable.printStackTrace();
       return new AdminFeign() {
           @Override
           public ResponseResult sensitives() {
               log.error("AdminFeign sensitives 远程调用出错啦 ~~~ !!!! {} ",throwable.getMessage());
               return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
           }

           @Override
           public ResponseResult findOne(Integer id) {
               log.info("参数: {}",id);
               log.error("AdminFeign findOne 远程调用出错啦 ~~~ !!!! {} ",throwable.getMessage());
               return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
           }

           // ================新增降级方法  start ================
           @Override
           public ResponseResult<List<AdChannel>> selectChannels() {
               log.error("AdminFeign selectChannels 远程调用出错啦 ~~~ !!!! {} ",throwable.getMessage());
               return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
           }
           // ================新增降级方法  end ================
       };
    }
}